package com.sdutcm.Controller;

import com.sdutcm.Domain.Attendance;
import com.sdutcm.Domain.Attendance2;
import com.sdutcm.Mapper.AttMapper;
import com.sdutcm.Service.AttService;
import com.sdutcm.Service.ServiceImpl.AttServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import javax.websocket.server.PathParam;
import java.util.List;
import java.util.Map;

/*
 *@Author Yan
 *@Create 2019-08-24 10:08
 */
@Controller
public class AttController {

    @Autowired
    private AttServiceImpl attService;

//    @GetMapping("/att1201list")
//    public String attfind(Map map) throws Exception {
//        map.put("attfind",attService.attfind());
//        return "Att1201-list";
//    }

    @Autowired
    private AttMapper attMapper;

   @GetMapping("/att1201edit")
   public String attfind(Map map) throws Exception {
        map.put("time1",attMapper.attfind(1));
       attMapper.clearup();
        map.put("time2",attMapper.attfind(2));
       attMapper.clearup();
        map.put("time3",attMapper.attfind(3));
       attMapper.clearup();
        map.put("time4",attMapper.attfind(4));
       attMapper.clearup();
        map.put("time5",attMapper.attfind(5));
       attMapper.clearup();
        map.put("time6",attMapper.attfind(6));
       attMapper.clearup();
        map.put("time7",attMapper.attfind(7));
       attMapper.clearup();
        map.put("time8",attMapper.attfind(8));
       attMapper.clearup();
        map.put("time9",attMapper.attfind(9));
       attMapper.clearup();
        map.put("time10",attMapper.attfind(10));
       attMapper.clearup();
        map.put("time11",attMapper.attfind(11));
       attMapper.clearup();
        map.put("time12",attMapper.attfind(12));
       attMapper.clearup();
        map.put("time13",attMapper.attfind(13));
       attMapper.clearup();
        map.put("time14",attMapper.attfind(14));
       attMapper.clearup();
        map.put("time15",attMapper.attfind(15));
       attMapper.clearup();
       return "Att1201-edit";
   }

   @PostMapping("/att1201edit")
   public String att1201edit(Attendance attendance) throws Exception {
       attService.att1201edit(attendance);
       return "redirect:/att1201list";
   }

    @PostMapping("/attadminedit")
    public String attAdminedit(Attendance attendance) throws Exception {
        System.out.println(attendance);
        attService.attAdminedit(attendance);
        return "redirect:/att1201list";
    }

   @GetMapping("/att1201list")
    public String find1201list(Map map) throws Exception {
       map.put("one1",attMapper.att1201list(1));
       map.put("one2",attMapper.att1201list(2));
       map.put("one3",attMapper.att1201list(3));
       map.put("one4",attMapper.att1201list(4));
       map.put("one5",attMapper.att1201list(5));
       map.put("one6",attMapper.att1201list(6));
       map.put("one7",attMapper.att1201list(7));
       map.put("one8",attMapper.att1201list(8));
       map.put("one9",attMapper.att1201list(9));
       map.put("one10",attMapper.att1201list(10));
       map.put("one11",attMapper.att1201list(11));
       map.put("one12",attMapper.att1201list(12));
       map.put("one13",attMapper.att1201list(13));
       map.put("one14",attMapper.att1201list(14));
       map.put("one15",attMapper.att1201list(15));
       return "Att1201-list";
   }

    @GetMapping("/attAdminlist")
    public String findAdminlist(Map map) throws Exception {
        map.put("two1",attMapper.att1201listA(1));
        map.put("two2",attMapper.att1201listA(2));
        map.put("two3",attMapper.att1201listA(3));
        map.put("two4",attMapper.att1201listA(4));
        map.put("two5",attMapper.att1201listA(5));
        map.put("two6",attMapper.att1201listA(6));
        map.put("two7",attMapper.att1201listA(7));
        map.put("two8",attMapper.att1201listA(8));
        map.put("two9",attMapper.att1201listA(9));
        map.put("two10",attMapper.att1201listA(10));
        map.put("two11",attMapper.att1201listA(11));
        map.put("two12",attMapper.att1201listA(12));
        map.put("two13",attMapper.att1201listA(13));
        map.put("two14",attMapper.att1201listA(14));
        map.put("two15",attMapper.att1201listA(15));
        return "Attadmin-list";
    }

   @GetMapping("/attdelete/{id}/{a_id}")
    public String attdeleteById(@PathVariable("id") String s_id,@PathVariable("a_id") String a_id) throws Exception {
       attService.attdeleteById(s_id,a_id);
       return "redirect:/att1201list";
   }

    @GetMapping("/attAdminedit")
    public String attfind2(Map map) throws Exception {
        map.put("time01",attMapper.attfind(1));
        attMapper.clearup();
        map.put("time02",attMapper.attfind(2));
        attMapper.clearup();
        map.put("time03",attMapper.attfind(3));
        attMapper.clearup();
        map.put("time04",attMapper.attfind(4));
        attMapper.clearup();
        map.put("time05",attMapper.attfind(5));
        attMapper.clearup();
        map.put("time6",attMapper.attfind(6));
        attMapper.clearup();
        map.put("time07",attMapper.attfind(7));
        attMapper.clearup();
        map.put("time08",attMapper.attfind(8));
        attMapper.clearup();
        map.put("time09",attMapper.attfind(9));
        attMapper.clearup();
        map.put("time010",attMapper.attfind(10));
        attMapper.clearup();
        map.put("time011",attMapper.attfind(11));
        attMapper.clearup();
        map.put("time012",attMapper.attfind(12));
        attMapper.clearup();
        map.put("time013",attMapper.attfind(13));
        attMapper.clearup();
        map.put("time014",attMapper.attfind(14));
        attMapper.clearup();
        map.put("time15",attMapper.attfind(15));
        attMapper.clearup();
        return "Attadmin-edit";
    }

    @GetMapping("/deleteTable")
    public String declearTable() throws Exception {
       attMapper.declearTable();
       return "index";
    }
}
